# -*- coding: utf-8 -*-
from apps import db
from datetime import datetime
from flask_login import UserMixin

from . import login_manager

class user_info(db.Model):
    __tablename__ = 'user_info'

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.String(255))
    name = db.Column(db.String(255))
    gender = db.Column(db.String(255))
    nationality = db.Column(db.String(255))
    province = db.Column(db.String(255))
    gk_score = db.Column(db.String(255))
    department = db.Column(db.String(255))
    major = db.Column(db.String(255))
    campus = db.Column(db.String(255))
    occupation = db.Column(db.String(255))
    gpa1 = db.Column(db.Float)
    gpa2 = db.Column(db.Float)
    gpa3 = db.Column(db.Float)
    gpa4 = db.Column(db.Float)
    gpa5 = db.Column(db.Float)
    gpa6 = db.Column(db.Float)
    gpa7 = db.Column(db.Float)
    gpa8 = db.Column(db.Float)
    GPA =  db.Column(db.Float)
    type = db.Column(db.String(255))
    xueji = db.Column(db.String(255))
    guojiaxueji = db.Column(db.String(255))
    year = db.Column(db.Integer)


#使用Flask_Login需要使要验证的实体对象（models.py中的Users对象）继承自UserMixin类
class ADMIN(UserMixin,db.Model):
    __tablename__ = 'ADMIN'
    UID = db.Column(db.String(255),primary_key=True)
    name = db.Column(db.String(255))
    PASSWD = db.Column (db.String (255))
    roles=db.Column(db.String(255))
    id=db.Column(db.Integer)



#用户认证的回调函数
@login_manager.user_loader
def load_user(id):
    return ADMIN.query.get(int(id))

class nationnality(db.Model):
    __tablename__ = 'nationnality'

    id = db.Column(db.Integer, primary_key=True)
    year = db.Column(db.Integer)
    nationality = db.Column(db.String(255))
    department = db.Column(db.String(255))
    people_count = db.Column(db.Integer)

class teacher(db.Model):
    __tablename__ = 'teacher'

    t_uid = db.Column(db.Integer, primary_key=True)
    duties = db.Column(db.String(255))
    name = db.Column(db.String(255))
    department = db.Column(db.String(255))
    nationality = db.Column(db.String(255))
    year = db.Column(db.Integer)
    professional = db.Column(db.String(255))
    gender = db.Column(db.String(255))

class Place(db.Model):
    __tablename__ = 'place'

    id=db.Column(db.Integer,primary_key=True)
    place=db.Column(db.String(255))
    gpa1 = db.Column(db.Float)
    gpa2 = db.Column(db.Float)
    gpa3 = db.Column(db.Float)
    gpa4 = db.Column(db.Float)
    gpa5 = db.Column(db.Float)
    gpa6 = db.Column(db.Float)
    gpa7 = db.Column(db.Float)
    gpa8 = db.Column(db.Float)

class Department(db.Model):
    __tablename__ = 'department'

    id=db.Column(db.Integer,primary_key=True)
    department=db.Column(db.String(255))
    gpa1=db.Column(db.Float)
    gpa2 = db.Column(db.Float)
    gpa3 = db.Column(db.Float)
    gpa4 = db.Column(db.Float)
    gpa5 = db.Column(db.Float)
    gpa6 = db.Column(db.Float)
    gpa7 = db.Column(db.Float)
    gpa8 = db.Column(db.Float)

class View_card_trjn(db.Model):
    __tablename__='VIEW_CARD_TRJN'

    id=db.Column(db.Integer,primary_key=True)
    userid=db.Column(db.String(255))
    idserial=db.Column(db.String(255))
    username=db.Column(db.String(255))
    sex=db.Column(db.String(255))
    doorctrlcode=db.Column(db.String(255))
    doorctrlname=db.Column(db.String(255))
    doorcode=db.Column(db.String(255))
    acctime=db.Column(db.DateTime, default=datetime.now())
    eventflag=db.Column(db.String(255))
    eventstatus=db.Column(db.String(255))
    eventss=db.Column(db.String(255))
    deptname=db.Column(db.String(255))
    pname=db.Column(db.String(255))
    cardid=db.Column(db.String(255))
    cardno=db.Column(db.String(255))



class late (db.Model):
    __tablename__ = 'late'
    id = db.Column (db.Integer, primary_key=True)
    idserial = db.Column (db.String (255))
    userid = db.Column (db.String (255))
    late_time = db.Column (db.DateTime)
    state = db.Column (db.Boolean, default=False)
    status = db.Column (db.String (255))




class userlate (db.Model):
    __tablename__ = 'userlate'
    idserial = db.Column (db.String (255), primary_key=True)
    latenum = db.Column (db.String (255))
    lasttime =db.Column (db.DateTime)
    missstatus =db. Column (db.Boolean, default=False)
    latestatus = db.Column (db.Boolean, default=False)
    missnum = db.Column (db.String (255))
    eventss= db.Column (db.String (255))
    averamount=db.Column (db.String (255))
    averstatus=db.Column (db.Boolean, default=False)
    avernum=db.Column (db.String (255))
    important=db.Column (db.Boolean, default=False)
    studynum = db.Column (db.String (255))
    failnum=db.Column(db.Integer) #挂科数量
    failstatus=db.Column (db.Boolean) #挂科处理

class dbuserinfo(db.Model):
    __tablename__ = 'userinfo'

    userid=db.Column (db.String (255),primary_key=True)
    name=db.Column (db.String (255))
    department=db.Column (db.String (255))
    class_=db.Column (db.String (255))
    major=db.Column (db.String (255))
    sex=db.Column (db.String (255))
    arriveearly=db.Column(db.Integer) #早到
    arrivelate=db.Column(db.Integer) #晚到
    arrivenot=db.Column(db.Integer) #未到
    aut=db.Column (db.String (255))
class userlog(db.Model):
    __tablename__ = 'userlog'
    id=db.Column(db.Integer,primary_key=True) #未到
    uid=db.Column (db.String (255),primary_key=True)
    devicenum=db.Column (db.String (255))
    time=db.Column(db.DateTime, default=datetime.now())
    flag=db.Column (db.String (255))







# #加载用户的回调函数
# @login_manager.user_loader
# def load_user(user_id):
#     return ADMIN.query.get(int(user_id))

